package com.harvey.coding.lambda.stream;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class StreamConstruct {
    public void streamFromValues() {
        Stream<Integer> intStream = Stream.of(1, 2, 3, 4, 5);
        intStream.forEach(System.out::print);
    }

    public void streamFromArray() {
        int[] ints = new int[]{1, 2, 3, 4, 5};
        IntStream intStream = Arrays.stream(ints);
        intStream.forEach(System.out::print);
    }

    public void streamFromFile() throws URISyntaxException, IOException {
        Stream<String> fileContents = Files.lines(Paths.get("E:\\JavaSpace\\simplify-coding\\src\\main\\resources"));
        fileContents.forEach(System.out::print);
    }

    public void streamFromFunction() {
        Stream<Integer> infinitIntStreamByIterate = Stream.iterate(0, n -> n + 1);
        infinitIntStreamByIterate.forEach(System.out::println);

        Stream<Double> infinitDoubleStreamByGen = Stream.generate(Math::random);
        infinitDoubleStreamByGen.forEach(System.out::println);
    }
}
